﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class LeadMilestoneRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();
        
        public LeadMilestone GetSingle(int leadId, int milestoneId)
        {
            return (from _object in entities.LeadMilestones where _object.LeadId == leadId && _object.MilestoneId == milestoneId select _object).FirstOrDefault();
        }

        public void Create(LeadMilestone _object)
        {
            entities.AddToLeadMilestones(_object);
            entities.SaveChanges();
        }

        public void Update(LeadMilestone _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int leadId, int milestoneId)
        {
            var _object = (from _list in entities.LeadMilestones where _list.LeadId == leadId && _list.MilestoneId == milestoneId select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
        public void Save(LeadMilestone _object)
        {
            _object.EntityKey = (from LeadMilestone ac in entities.LeadMilestones where ac.LeadId == _object.LeadId && ac.MilestoneId == _object.MilestoneId select ac).FirstOrDefault().EntityKey;
            entities.SaveChanges();
        }
    }
}